/*   1:    */ package org.jetbrains.debugger;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.AsyncResult;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.PairConsumer;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.xdebugger.ObsolescentAsyncResults;
import com.intellij.xdebugger.frame.XCompositeNode;
import com.intellij.xdebugger.frame.XValueChildrenList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.debugger.values.Value;
import org.jetbrains.debugger.values.ValueType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */ 
/*  23:    */ public final class Variables
/*  24:    */ {
/*  25:    */   public static final String SPECIAL_PROPERTY_PREFIX = "__";
/*  26: 26 */   private static final Pattern a = Pattern.compile("^function[\\t ]*\\(");
/*  27: 28 */   private static final Comparator<Variable> b = new Comparator()
/*  28:    */   {
/*  29:    */     public int compare(Variable paramAnonymousVariable1, Variable paramAnonymousVariable2)
/*  30:    */     {
/*  31: 31 */       return Variables.a(paramAnonymousVariable1.getName(), paramAnonymousVariable2.getName());
/*  32:    */     }
/*  33:    */   };
/*  34:    */   
/*  35:    */   public static void processScopeVariables(@NotNull Scope paramScope, @NotNull XCompositeNode paramXCompositeNode, @NotNull VariableContext paramVariableContext, @Nullable final ActionCallback paramActionCallback)
/*  36:    */   {
/*  37: 39 */     if (paramScope == null) {
/*  38: 39 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/Variables", "processScopeVariables" }));
/*  39:    */     }
/*  40: 39 */     if (paramXCompositeNode == null) {
/*  41: 39 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/Variables", "processScopeVariables" }));
/*  42:    */     }
/*  43: 39 */     if (paramVariableContext == null) {
/*  44: 39 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/debugger/Variables", "processScopeVariables" }));
/*  45:    */     }
/*  46: 39 */     final boolean bool = paramActionCallback == null;
/*  47: 40 */     AsyncResult localAsyncResult = ObsolescentAsyncResults.consume(paramScope.getVariables(), paramXCompositeNode, new PairConsumer()
/*  48:    */     {
/*  49:    */       public void consume(List<Variable> paramAnonymousList, XCompositeNode paramAnonymousXCompositeNode)
/*  50:    */       {
/*  51: 44 */         ArrayList localArrayList = new ArrayList(paramAnonymousList.size());
/*  52: 45 */         SmartList localSmartList = new SmartList();
/*  53: 46 */         for (Variable localVariable : paramAnonymousList) {
/*  54: 47 */           if (this.val$context.getMemberFilter().isMemberVisible(localVariable, false))
/*  55:    */           {
/*  56: 48 */             Value localValue = localVariable.getValue();
/*  57: 49 */             if ((localValue != null) && (localValue.getType() == ValueType.FUNCTION) && (localValue.getValueString() != null) && (!Variables.a.matcher(localValue.getValueString()).lookingAt())) {
/*  58: 53 */               localSmartList.add(localVariable);
/*  59:    */             } else {
/*  60: 56 */               localArrayList.add(localVariable);
/*  61:    */             }
/*  62:    */           }
/*  63:    */         }
/*  64: 61 */         Variables.a(localArrayList);
/*  65: 62 */         Variables.a(localSmartList);
/*  66: 64 */         if (!localArrayList.isEmpty()) {
/*  67: 65 */           paramAnonymousXCompositeNode.addChildren(Variables.createVariablesList(localArrayList, this.val$context), (localSmartList.isEmpty()) && (bool));
/*  68:    */         }
/*  69: 68 */         if (!localSmartList.isEmpty()) {
/*  70: 69 */           paramAnonymousXCompositeNode.addChildren(XValueChildrenList.bottomGroup(new VariablesGroup("Functions", localSmartList, this.val$context)), bool);
/*  71: 71 */         } else if ((bool) && (localArrayList.isEmpty())) {
/*  72: 72 */           paramAnonymousXCompositeNode.addChildren(XValueChildrenList.EMPTY, true);
/*  73:    */         }
/*  74: 75 */         if (!bool) {
/*  75: 76 */           paramActionCallback.setDone();
/*  76:    */         }
/*  77:    */       }
/*  78:    */     });
/*  79: 80 */     if (!bool) {
/*  80: 81 */       localAsyncResult.notifyWhenRejected(paramActionCallback);
/*  81:    */     }
/*  82:    */   }
/*  83:    */   
/*  84:    */   @Nullable
/*  85:    */   public static List<Variable> sortFilterAndAddValueList(@NotNull List<? extends Variable> paramList, @NotNull XCompositeNode paramXCompositeNode, @NotNull VariableContext paramVariableContext, int paramInt, boolean paramBoolean)
/*  86:    */   {
/*  87: 91 */     if (paramList == null) {
/*  88: 91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/Variables", "sortFilterAndAddValueList" }));
/*  89:    */     }
/*  90: 91 */     if (paramXCompositeNode == null) {
/*  91: 91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/Variables", "sortFilterAndAddValueList" }));
/*  92:    */     }
/*  93: 91 */     if (paramVariableContext == null) {
/*  94: 91 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/debugger/Variables", "sortFilterAndAddValueList" }));
/*  95:    */     }
/*  96: 91 */     List localList = filterAndSort(paramList, paramVariableContext, true);
/*  97: 92 */     if (localList.isEmpty())
/*  98:    */     {
/*  99: 93 */       if (paramBoolean) {
/* 100: 94 */         paramXCompositeNode.addChildren(XValueChildrenList.EMPTY, true);
/* 101:    */       }
/* 102: 96 */       return null;
/* 103:    */     }
/* 104: 99 */     int i = Math.min(paramInt, localList.size());
/* 105:100 */     int j = i == localList.size() ? 1 : 0;
/* 106:101 */     paramXCompositeNode.addChildren(createVariablesList(localList, 0, i, paramVariableContext), (paramBoolean) && (j != 0));
/* 107:102 */     if (j != 0) {
/* 108:103 */       return null;
/* 109:    */     }
/* 110:106 */     paramXCompositeNode.tooManyChildren(localList.size() - i);
/* 111:107 */     return localList;
/* 112:    */   }
/* 113:    */   
/* 114:    */   public static List<Variable> filterAndSort(@NotNull List<? extends Variable> paramList, @NotNull VariableContext paramVariableContext, boolean paramBoolean)
/* 115:    */   {
/* 116:112 */     if (paramList == null) {
/* 117:112 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/Variables", "filterAndSort" }));
/* 118:    */     }
/* 119:112 */     if (paramVariableContext == null) {
/* 120:112 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/Variables", "filterAndSort" }));
/* 121:    */     }
/* 122:112 */     if (paramList.isEmpty()) {
/* 123:113 */       return Collections.emptyList();
/* 124:    */     }
/* 125:116 */     ArrayList localArrayList = new ArrayList(paramList.size());
/* 126:117 */     for (Variable localVariable : paramList) {
/* 127:118 */       if (paramVariableContext.getMemberFilter().isMemberVisible(localVariable, paramBoolean)) {
/* 128:119 */         localArrayList.add(localVariable);
/* 129:    */       }
/* 130:    */     }
/* 131:122 */     a(localArrayList);
/* 132:123 */     return localArrayList;
/* 133:    */   }
/* 134:    */   
/* 135:    */   private static void a(List<Variable> paramList)
/* 136:    */   {
/* 137:127 */     ContainerUtil.sort(paramList, b);
/* 138:    */   }
/* 139:    */   
/* 140:    */   private static int a(@Nullable String paramString1, @Nullable String paramString2)
/* 141:    */   {
/* 142:133 */     if (paramString1 == paramString2) {
/* 143:134 */       return 0;
/* 144:    */     }
/* 145:136 */     if (paramString1 == null) {
/* 146:137 */       return -1;
/* 147:    */     }
/* 148:139 */     if (paramString2 == null) {
/* 149:140 */       return 1;
/* 150:    */     }
/* 151:143 */     int i = paramString1.length();
/* 152:144 */     int j = paramString2.length();
/* 153:145 */     int k = 0;
/* 154:145 */     for (int m = 0; (k < i) && (m < j); m++)
/* 155:    */     {
/* 156:147 */       char c1 = paramString1.charAt(k);
/* 157:148 */       char c2 = paramString2.charAt(m);
/* 158:149 */       if (((StringUtil.isDecimalDigit(c1)) || (c1 == ' ')) && ((StringUtil.isDecimalDigit(c2)) || (c2 == ' ')))
/* 159:    */       {
/* 160:150 */         int n = k;
/* 161:151 */         while ((c1 == ' ') || (c1 == '0'))
/* 162:    */         {
/* 163:152 */           n++;
/* 164:153 */           if (n >= i) {
/* 165:    */             break;
/* 166:    */           }
/* 167:156 */           c1 = paramString1.charAt(n);
/* 168:    */         }
/* 169:158 */         int i1 = m;
/* 170:159 */         while ((c2 == ' ') || (c2 == '0'))
/* 171:    */         {
/* 172:160 */           i1++;
/* 173:161 */           if (i1 >= j) {
/* 174:    */             break;
/* 175:    */           }
/* 176:164 */           c2 = paramString2.charAt(i1);
/* 177:    */         }
/* 178:166 */         k = n;
/* 179:167 */         m = i1;
/* 180:169 */         while ((k < i) && (StringUtil.isDecimalDigit(paramString1.charAt(k)))) {
/* 181:170 */           k++;
/* 182:    */         }
/* 183:172 */         while ((m < j) && (StringUtil.isDecimalDigit(paramString2.charAt(m)))) {
/* 184:173 */           m++;
/* 185:    */         }
/* 186:175 */         int i2 = k - n - (m - i1);
/* 187:176 */         if (i2 != 0) {
/* 188:178 */           return i2;
/* 189:    */         }
/* 190:180 */         for (; n < k; i1++)
/* 191:    */         {
/* 192:182 */           int i3 = paramString1.charAt(n) - paramString2.charAt(i1);
/* 193:183 */           if (i3 != 0) {
/* 194:184 */             return i3;
/* 195:    */           }
/* 196:180 */           n++;
/* 197:    */         }
/* 198:187 */         k--;
/* 199:188 */         m--;
/* 200:    */       }
/* 201:190 */       else if (c1 != c2)
/* 202:    */       {
/* 203:191 */         if (c1 == '_') {
/* 204:192 */           return 1;
/* 205:    */         }
/* 206:194 */         if (c2 == '_') {
/* 207:195 */           return -1;
/* 208:    */         }
/* 209:198 */         return c1 - c2;
/* 210:    */       }
/* 211:146 */       k++;
/* 212:    */     }
/* 213:205 */     if (k < i) {
/* 214:206 */       return 1;
/* 215:    */     }
/* 216:208 */     if (m < j) {
/* 217:209 */       return -1;
/* 218:    */     }
/* 219:211 */     return i - j;
/* 220:    */   }
/* 221:    */   
/* 222:    */   public static XValueChildrenList createVariablesList(@NotNull List<Variable> paramList, @NotNull VariableContext paramVariableContext)
/* 223:    */   {
/* 224:215 */     if (paramList == null) {
/* 225:215 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/Variables", "createVariablesList" }));
/* 226:    */     }
/* 227:215 */     if (paramVariableContext == null) {
/* 228:215 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/debugger/Variables", "createVariablesList" }));
/* 229:    */     }
/* 230:215 */     return createVariablesList(paramList, 0, paramList.size(), paramVariableContext);
/* 231:    */   }
/* 232:    */   
/* 233:    */   public static XValueChildrenList createVariablesList(@NotNull List<Variable> paramList, int paramInt1, int paramInt2, @NotNull VariableContext paramVariableContext)
/* 234:    */   {
/* 235:219 */     if (paramList == null) {
/* 236:219 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/debugger/Variables", "createVariablesList" }));
/* 237:    */     }
/* 238:219 */     if (paramVariableContext == null) {
/* 239:219 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "3", "org/jetbrains/debugger/Variables", "createVariablesList" }));
/* 240:    */     }
/* 241:219 */     XValueChildrenList localXValueChildrenList = new XValueChildrenList(paramInt2 - paramInt1);
/* 242:    */     
/* 243:221 */     NonWatchableVariableContext localNonWatchableVariableContext = null;
/* 244:223 */     for (int i = paramInt1; i < paramInt2; i++)
/* 245:    */     {
/* 246:224 */       Variable localVariable = (Variable)paramList.get(i);
/* 247:225 */       localXValueChildrenList.add(new VariableView(localVariable, paramVariableContext));
/* 248:226 */       if ((localVariable instanceof ObjectProperty))
/* 249:    */       {
/* 250:227 */         ObjectProperty localObjectProperty = (ObjectProperty)localVariable;
/* 251:228 */         if (localObjectProperty.getGetter() != null)
/* 252:    */         {
/* 253:229 */           if (localNonWatchableVariableContext == null) {
/* 254:230 */             localNonWatchableVariableContext = new NonWatchableVariableContext(paramVariableContext);
/* 255:    */           }
/* 256:232 */           localXValueChildrenList.add(new VariableView(new VariableImpl("get " + localObjectProperty.getName(), localObjectProperty.getGetter()), localNonWatchableVariableContext));
/* 257:    */         }
/* 258:234 */         if (localObjectProperty.getSetter() != null)
/* 259:    */         {
/* 260:235 */           if (localNonWatchableVariableContext == null) {
/* 261:236 */             localNonWatchableVariableContext = new NonWatchableVariableContext(paramVariableContext);
/* 262:    */           }
/* 263:238 */           localXValueChildrenList.add(new VariableView(new VariableImpl("set " + localObjectProperty.getName(), localObjectProperty.getSetter()), localNonWatchableVariableContext));
/* 264:    */         }
/* 265:    */       }
/* 266:    */     }
/* 267:242 */     return localXValueChildrenList;
/* 268:    */   }
/* 269:    */   
/* 270:    */   private static class NonWatchableVariableContext
/* 271:    */     extends VariableContextWrapper
/* 272:    */   {
/* 273:    */     public NonWatchableVariableContext(VariableContext paramVariableContext)
/* 274:    */     {
/* 275:247 */       super(null);
/* 276:    */     }
/* 277:    */     
/* 278:    */     public boolean watchableAsEvaluationExpression()
/* 279:    */     {
/* 280:252 */       return false;
/* 281:    */     }
/* 282:    */   }
/* 283:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.debugger.Variables

 * JD-Core Version:    0.7.0.1

 */